﻿/***
 *
 * Title: 生化危机
 *
 * Description:
 * [当前脚本的具体作用]
 *
 * Author: sk9
 *
 * Date: 2014-10-03
 * 
 * Version: 1.0
 *
 * Modify Recorder:
 *
***/
using UnityEngine;
using System.Collections;

public class JoystickRotation : MonoBehaviour {
    private bool isPress = false;
    private Transform button;

    public static float h = 0;
    public static float v = 0;

    void Awake()
    {
        button = transform.Find("Button");
    }

    void OnPress(bool isPress)
    {
        this.isPress = isPress;
        if (!isPress)
        {
            button.localPosition = Vector3.zero;
            h = 0;
            v = 0;
        }
    }

    void Update()
    {
        if (isPress)
        {
            Vector2 touchPosition = UICamera.lastTouchPosition;
            touchPosition -= new Vector2(Screen.width - 150, 150);
            float distance = Vector2.Distance(Vector2.zero, touchPosition);
            if (distance > 122)
            {
                touchPosition = touchPosition.normalized *122;
            }
            button.localPosition = touchPosition;

            h = touchPosition.x / 122;
            v = touchPosition.y / 122;


        }
    }
}
